from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import os


class Test:
    def __init__(self):
        # 打开浏览器，访问注册实例页面
        self.driver = webdriver.Chrome()
        # 实例链接路径
        url = 'file:///' + os.path.abspath('html') + '/注册实例.html'
        self.driver.get(url)

    # 注册著框架页面
    def register(self):
        time.sleep(2)
        self.driver.find_element(By.ID, 'user').send_keys('admin')
        self.driver.find_element(By.ID, 'password').send_keys('123456')
        self.driver.find_element(By.ID, 'tel').send_keys('16477839932')
        self.driver.find_element(By.ID, 'email').send_keys('123@htm.com')
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button').click()

    # 注册实例A：
    def register_a(self):
        time.sleep(2)
        # 切换到A框架
        self.driver.switch_to.frame('myframe1')
        # 定位账号，密码，电话号码，电子邮件，注册按钮
        self.driver.find_element(By.ID, 'userA').send_keys('admin')
        self.driver.find_element(By.ID, 'passwordA').send_keys('123456')
        self.driver.find_element(By.ID, 'telA').send_keys('16577839932')
        self.driver.find_element(By.ID, 'emailA').send_keys('123@htm.com')
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button').click()

    def register_b(self):
        time.sleep(2)
        # 切换到B框架
        self.driver.switch_to.frame('myframe2')
        # 定位账号，密码，电话号码，电子邮件，注册按钮
        self.driver.find_element(By.ID, 'userB').send_keys('admin')
        self.driver.find_element(By.ID, 'passwordB').send_keys('123456')
        self.driver.find_element(By.ID, 'telB').send_keys('16377839932')
        self.driver.find_element(By.ID, 'emailB').send_keys('123@htm.com')
        time.sleep(2)
        self.driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button').click()

    def quit(self):
        time.sleep(2)
        self.driver.quit()


if __name__ == '__main__':
    b = Test()
    b.register()
    b.register_a()
    b.register_b()
    b.quit()
